package com.hien.starting;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.Align;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class ViewSurface extends View {
    Bitmap fish,blueFish;
    float changingX;
    float blueXchange;
    private String tag = "view surface";

    public ViewSurface(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);
	fish = BitmapFactory.decodeResource(getResources(), R.drawable.fish);
	blueFish = BitmapFactory.decodeResource(getResources(), R.drawable.bluefish);
	changingX = 0;
	blueXchange = 320;
    }

    public ViewSurface(Context context, AttributeSet attrs) {
	this(context, attrs, 0);
    }

    public ViewSurface(Context context) {
	this(context, null, 0);
    }

    @Override
    protected void onDraw(Canvas canvas) {
	// TODO Auto-generated method stub
	super.onDraw(canvas);
	blueXchange += canvas.getWidth();
	canvas.drawColor(Color.TRANSPARENT);
	canvas.drawBitmap(fish, changingX, (canvas.getHeight() / 6), null);
	canvas.drawBitmap(blueFish, blueXchange,(canvas.getHeight()/8),null);
	if (changingX < canvas.getWidth()) {
	    changingX += 5;
	} else {
	    changingX = 0;
	}
	/*if(blueXchange > 0){
	    Log.i(tag , "ve con ca xanh" + blueXchange);
	    blueXchange = blueXchange - 15;
	    
	}
	else
	    blueXchange = 320;*/
	
	invalidate();
    }

}
